package com.youlai.boot.modules.bfapp.controller;

import com.youlai.boot.modules.bfapp.service.BfAppService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.modules.bfapp.model.form.BfAppForm;
import com.youlai.boot.modules.bfapp.model.query.BfAppQuery;
import com.youlai.boot.modules.bfapp.model.vo.BfAppVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 客户端管理前端控制层
 *
 * @author maoyu
 * @since 2025-03-14 11:08
 */
@Tag(name = "客户端管理接口")
@RestController
@RequestMapping("/api/v1/bfApps")
@RequiredArgsConstructor
public class BfAppController  {

    private final BfAppService bfAppService;

    @Operation(summary = "客户端管理分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('modules:bfApp:query')")
    public PageResult<BfAppVO> getBfAppPage(BfAppQuery queryParams ) {
        IPage<BfAppVO> result = bfAppService.getBfAppPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增客户端管理")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('modules:bfApp:add')")
    public Result<Void> saveBfApp(@RequestBody @Valid BfAppForm formData ) {
        boolean result = bfAppService.saveBfApp(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取客户端管理表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('modules:bfApp:edit')")
    public Result<BfAppForm> getBfAppForm(
        @Parameter(description = "客户端管理ID") @PathVariable Long id
    ) {
        BfAppForm formData = bfAppService.getBfAppFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改客户端管理")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('modules:bfApp:edit')")
    public Result<Void> updateBfApp(
            @Parameter(description = "客户端管理ID") @PathVariable Long id,
            @RequestBody @Validated BfAppForm formData
    ) {
        boolean result = bfAppService.updateBfApp(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除客户端管理")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('modules:bfApp:delete')")
    public Result<Void> deleteBfApps(
        @Parameter(description = "客户端管理ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = bfAppService.deleteBfApps(ids);
        return Result.judge(result);
    }
}
